<?php
    @header("Content-type:text/html;chaset=utf-8");
    @include_once("conn.php");
    
    $obj = array();

    $user = $_GET["user"];

    if(!$user){
        $obj["status"] = false;
        $obj["detail"] = "请输入完整的参数";
        exit(json_encode($obj));
    }

    $sql = "select c.id,c.gId,c.buyNum,g.goodsName,g.goodsImg,g.goodsPrice from `cart` as c,`goodslist` as g where c.gId = g.goodsId and user = '$user' ";
    
    $result = mysqli_query($conn,$sql);
   
    $all = array();

    while($item = mysqli_fetch_assoc($result)){
        //数据预处理
        $item["total"] = $item["buyNum"] * $item["goodsPrice"];
        //把单条数据整合起来
        array_push($all,$item);
    }

    // print_r($item);

    if (count($all)) {
        $obj["status"] = true;
        $obj["detail"] = "succeed";
        $obj["list"] = $all;
    }else{
        $obj["status"] = false;
        $obj["detail"] = "fail";
    }

    echo json_encode($obj);